#pragma once
#include"hashtable.h"
namespace egghead
{

	template<class K>struct HashFunc;
	template<class K, class V,class HASHFUNC = HashFunc<K>>
	class unordered_map
	{
		struct GETVAL
		{
			const K& operator()(const pair<const K, V>& kv) { return kv.first; }
		};
		typedef typename hashbucket::HashTable<const K, pair<const K, V>, HASHFUNC, GETVAL>::iterater iterater;
		typedef typename hashbucket::HashTable<const K, pair<const K, V>, HASHFUNC, GETVAL>::const_iterater const_iterater;

	public:
		pair<iterater, bool> insert(const pair<const K, V>& kv)
		{
			return hashtable.insert(kv);
		}

		bool erase(const K& k)
		{
			return hashtable.erase(k);
		}
		iterater find(const K& k)
		{
			return hashtable.find(k);
		}
		V& operator[](const K& k)
		{
			return hashtable.insert({ k,V() }).first->second;
		}

		unordered_map<K, HASHFUNC>operator ==(const unordered_map<K, HASHFUNC>& other)
		{
			hashtable = other.hashtable;
		}
		iterater begin() { return hashtable.begin(); }
		iterater end() { return hashtable.end(); }
		const_iterater begin()const { return hashtable.begin(); }
		const_iterater end()const { return hashtable.end(); }

	private:
		hashbucket::HashTable<const K, pair<const K,V>, HASHFUNC, GETVAL>hashtable;
	};
}
